package mongo

import (
	"go.mongodb.org/mongo-driver/mongo"
)

func InsertOne(db_name, table_name string, data any) {
	MongoShell(db_name, table_name, ActionInsertOne, nil, data)
}

func ReplaceOne(db_name, table_name string, filter any, data any) *mongo.UpdateResult {
	if ret := MongoShell(db_name, table_name, ActionReplaceOne, filter, data); ret != nil {
		return ret.Data.(*mongo.UpdateResult)
	}
	return nil
}

func UpdateOne(db_name, table_name string, filter any, data any) {
	MongoShell(db_name, table_name, ActionUpdateOne, filter, data)
}

func DeleteOne(db_name, table_name string, filter any, opts ...any) {
	MongoShell(db_name, table_name, ActionDeleteOne, filter, nil, opts...)
}

func DeleteMany(db_name, table_name string, filter any) {
	MongoShell(db_name, table_name, ActionDeleteMany, filter, nil)
}

func Replace2InsertOne(db_name, table_name string, filter any, data any) {
	if ret := ReplaceOne(db_name, table_name, filter, data); ret != nil {
		if ret.MatchedCount > 0 {
			return
		}
	}

	InsertOne(db_name, table_name, data)
}
